package com.yiquan.sms.listen;

import com.yiquan.sms.utils.SmsUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author Tyrone
 * @date 2021/12/24 21:39
 */
@Component
@RabbitListener(queues = "yiquan_sms")
@Slf4j
public class SmsListener {

    @Autowired
    private SmsUtils smsUtils;

    /**
     * 从rabbitMq拉取信息解耦
     * @param mes
     */
    @RabbitHandler
    public void sendSms(Map<String,String> mes){
        try {
            boolean sendStatus = smsUtils.sendSmsAli(mes.get("phone"), mes.get("code"));
            if (sendStatus){
                log.info("手机发送成功");
            }

        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
